#pragma once
#include "../stdafx.h"
#include "meshGeo.h"
#include "material.h"
#include "renderitem.h"
#include "../renderer.h"
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags

using namespace DirectX;

class ModelLoader
{
public:
	ModelLoader(Renderer* ptr, const XMMATRIX& mat);
	~ModelLoader();

	bool loadModel(const std::string& pFile, UINT& objIdx, UINT& matCBIndex, UINT& texIndex);

	void Close();

private:
	Renderer* pRender;
	std::unique_ptr<MeshGeometry> geo;
	std::vector<Vertex> vertices;
	std::vector<std::uint16_t> indices;
	UINT voffset = 0;
	UINT ioffset = 0;

	XMMATRIX model_matrix;
	std::string model_name;
	std::string directory;
	std::string textype;
	std::vector<Texture> textures_loaded;

	UINT m_objIdx, m_matCBIndex, m_texIndex;


	void processNode(aiNode* node, const aiScene* scene);
	void processMesh(aiMesh* mesh, const aiScene* scene);
	
	void loadMaterialTextures(aiMaterial* mat, aiTextureType type, const std::string& typeName, const aiScene* scene);
	std::string determineTextureType(const aiScene* scene, aiMaterial* mat);
	int getTextureIndex(aiString* str);
	void getTextureFromModel(const aiScene* scene, int textureindex, const std::string& typeName);
	/**/
};